import type { AxiosResponse } from 'axios';

import { requestClient } from '#/api/request';

export namespace MdItemAPI {
  export interface Row {
    searchValue: any;
    createBy: string;
    createTime: string;
    updateBy: any;
    attr1: any;
    attr2: any;
    attr3: any;
    attr4: any;
    batchFlag: string;
    enableFlag: string;
    highValue: string;
    itemCode: string;
    itemId: number;
    itemName: string;
    itemOrProduct: string;
    itemTypeCode: string;
    itemTypeId: number;
    itemTypeName: string;
    maxStock: number;
    minStock: number;
    params: any;
    remark: string;
    safeStockFlag: string;
    specification: string;
    unitName: string;
    unitOfMeasure: string;
    updateTime: any;
  }
  export interface TreeselectResult {
    msg: string;
    code: number;
    data: [];
  }
  export interface GetMdItemResult {
    total: number;
    rows: Row[];
    code: number;
    msg: string;
  }
  export interface CreateMdItemResult {
    msg: string;
    code: number;
    data: [];
  }
}
export namespace MaterialsTree {
  export interface FluffyChild {
    id: number;
    label: string;
  }
  export interface PurpleChild {
    id: number;
    label: string;
    children?: FluffyChild[];
  }
  export interface DatumChild {
    id: number;
    label: string;
    children: PurpleChild[];
  }
  export interface Datum {
    id: number;
    label: string;
    children: DatumChild[];
  }

  export interface GetListReturn {
    msg: string;
    code: number;
    data: Datum[];
  }
}
// 请求数据材料分类
export const Materials = () => {
  return requestClient.get<AxiosResponse<MdItemAPI.TreeselectResult>>(
    '/mes/md/itemtype/treeselect',
  );
};
// 请求表格数据
// export const GetMdItem = () => {
//   return requestClient.get<MdItemAPI.GetMdItemResult>(
//     '/mes/md/mditem/list?pageNum=1&pageSize=10&itemTypeId=0',
//   );
// };

// 请求数据材料分类树
export const MaterialsTree = () => {
  return requestClient.get<MaterialsTree.GetListReturn>(
    '/mes/md/itemtype/treeselect',
  );
};
export const GetMdItem = (params?: {
  itemTypeId?: number;
  page?: number;
  pageSize?: number;
}) => {
  return requestClient.get<MdItemAPI.GetMdItemResult>('/mes/md/mditem/list', {
    params,
  });
};

export const CreateMdItem = () => {
  return requestClient.get<AxiosResponse<MdItemAPI.CreateMdItemResult>>(
    '/system/dict/data/type/mes_item_product',
  );
};

// 删除数据
export const DeleteMdItem = (id: string) => {
  return requestClient.delete<MdItemAPI.GetMdItemResult>(
    `/mes/md/mditem/${id}`,
  );
};
